package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ledi.guns.common.persistence.model.vo.HelpVo;
import com.ledi.guns.common.persistence.model.vo.TypeVo;
import com.ledi.guns.common.persistence.page.OrderType;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.core.base.tips.Tip;
import com.ledi.guns.modular.ledipay.controller.req.clazz.ClassAdd.Add;
import com.ledi.guns.modular.ledipay.controller.req.clazz.ClassAdd.Delete;
import com.ledi.guns.modular.ledipay.controller.req.clazz.ClassAdd.Update;
import com.ledi.guns.modular.ledipay.controller.req.help.HelpCenterAdd;
import com.ledi.guns.modular.ledipay.controller.req.help.QuestionReq;
import com.ledi.guns.modular.ledipay.controller.req.help.TypeAdd;
import com.ledi.guns.modular.ledipay.controller.req.help.TypeReq;
import com.ledi.guns.modular.ledipay.service.HelpCenterService;

/**
 * 文件名称： com.ledi.guns.modular.ledipay.controller.HelpCenterController.java<br/>
 * 初始作者： 钟小平<br/>
 * 创建日期： 2018年9月13日<br/>
 * 功能说明： 帮助中心 Controller<br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (乐迪教育科技有限公司-幼儿事业部) 2017-2018.All rights reserved.<br/>
 */
@Api
@RestController
@RequestMapping(value = "/help")
public class HelpCenterController {

	@Resource
	private HelpCenterService helpCenterService;

	/**
	 * @api {POST} /help/typeList 分类列表
	 * @apiVersion 1.5.0
	 * @apiGroup help
	 * @apiName typeList
	 * @apiParam {String} title 标题
	 * @apiSuccess {int} id 分类id
	 * @apiSuccess {String} name 问题分类名称
	 * @apiSuccess {String} helpCount 问题总数（个）
	 * @apiSuccess {Date} updateTime 更新时间
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "asc": true,
	 *                    "condition": "",
	 *                    "current": 1,
	 *                    "limit": 2147483647,
	 *                    "offset": 0,
	 *                    "offsetCurrent": 0,
	 *                    "openSort": true,
	 *                    "orderByField": "",
	 *                    "pages": 1,
	 *                    "records": [
	 *                    {
	 *                    "helpCount": 0,
	 *                    "id": 1,
	 *                    "name": "常见分类",
	 *                    "orderNumber": 0,
	 *                    "updateTime": "2018-09-13 13:26:07"
	 *                    },
	 *                    {
	 *                    "helpCount": 0,
	 *                    "id": 2,
	 *                    "name": "未分类问题",
	 *                    "orderNumber": -1,
	 *                    "updateTime": "2018-09-13 13:26:40"
	 *                    }
	 *                    ],
	 *                    "searchCount": true,
	 *                    "size": 10,
	 *                    "total": 2
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/typeList", method = RequestMethod.POST)
	// @Permission
	public Object typeList(@RequestBody TypeReq query) {

		query.checkOrder(TypeVo.class);
		query.setOrderBy("orderNumber");
		query.setOrderType(OrderType.ASC);
		Page<TypeVo> page = helpCenterService.pageTypeList(new Page<TypeVo>(query.getPageNo(), query.getPageSize()), query);
		return SuccessTip.buildSuccess(page);
	}

	/**
	 * @api {POST} /help/typeAdd 增加类型
	 * @apiGroup help
	 * @apiName typeAdd
	 * @apiParam {String} name 类型名称
	 * @apiParam {int} orderNumber 序号
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/typeAdd", method = RequestMethod.POST)
	public Tip addType(@RequestBody @Validated({ Add.class }) TypeAdd typeAdd) {

		helpCenterService.addType(typeAdd);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {PUT} /help/typeUpdate 修改类型
	 * @apiGroup help
	 * @apiName typeUpdate
	 * @apiParam {int} id id
	 * @apiParam {String} name 类型名称
	 * @apiParam {int} orderNumber 序号
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/typeUpdate", method = RequestMethod.PUT)
	public Tip typeUpdate(@RequestBody @Validated({ Update.class }) TypeAdd typeAdd) {

		helpCenterService.addType(typeAdd);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {POST} /help/removeType/{id} 删除类型
	 * @apiGroup help
	 * @apiName removeType
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/removeType/{id}", method = RequestMethod.DELETE)
	public Tip removeType(@PathVariable("id") Long id) {

		helpCenterService.removeType(id);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {POST} /help/helpList 问题列表
	 * @apiVersion 1.5.0
	 * @apiGroup help
	 * @apiName helpList
	 * @apiParam {String} title 标题
	 * @apiParam {Integer} typeId 分类id
	 * @apiParam {Integer} source 来源
	 * @apiSuccess {String} title 标题
	 * @apiSuccess {String} typeName 问题分类名称
	 * @apiSuccess {String} isNomal 是否为常见问题
	 * @apiSuccess {String} source 来源
	 * @apiSuccess {Date} updateTime 更新时间
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "asc": true,
	 *                    "condition": "",
	 *                    "current": 1,
	 *                    "limit": 2147483647,
	 *                    "offset": 0,
	 *                    "offsetCurrent": 0,
	 *                    "openSort": true,
	 *                    "orderByField": "",
	 *                    "pages": 1,
	 *                    "records": [
	 *                    {
	 *                    "content": "内容111",
	 *                    "id": 1,
	 *                    "isNomal": 0,
	 *                    "isNomalZh": "",
	 *                    "source": "0",
	 *                    "title": "标题",
	 *                    "typeId": "",
	 *                    "typeName": "分类2",
	 *                    "updateTime": "2018-09-14 14:32:23"
	 *                    }
	 *                    ],
	 *                    "searchCount": true,
	 *                    "size": 10,
	 *                    "total": 1
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/helpList", method = RequestMethod.POST)
	// @Permission
	public Object helpList(@RequestBody QuestionReq query) {

		query.checkOrder(HelpVo.class);
		Page<HelpVo> page = helpCenterService.pageHelpList(new Page<HelpVo>(query.getPageNo(), query.getPageSize()), query);
		return SuccessTip.buildSuccess(page);
	}

	/**
	 * @api {POST} /help/helpAdd 增加问题
	 * @apiGroup help
	 * @apiName helpAdd
	 * @apiParam {String} title 标题名称
	 * @apiParam {String} content 内容名称
	 * @apiParam {int} typeId 类型id
	 * @apiParam {int} source 渠道0学校1代理商
	 * @apiParam {int} isNomal 是否常见0否1是
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/helpAdd", method = RequestMethod.POST)
	public Tip helpAdd(@RequestBody @Validated({ Add.class }) HelpCenterAdd helpCenterAdd) {

		helpCenterService.addHelp(helpCenterAdd);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {PUT} /help/helpMerge 编辑问题
	 * @apiGroup help
	 * @apiName helpMerge
	 * @apiParam {int} id ID
	 * @apiParam {int} versionNo 版本号
	 * @apiParam {String} title 标题名称
	 * @apiParam {String} content 内容名称
	 * @apiParam {int} typeId 类型id
	 * @apiParam {String} source 渠道0学校1代理商
	 * @apiParam {int} isNomal 是否常见0否1是
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/helpMerge", method = RequestMethod.PUT)
	public Tip helpMerge(@RequestBody @Validated({ Update.class }) HelpCenterAdd helpCenterAdd) {

		helpCenterService.addHelp(helpCenterAdd);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {DELETE} /help/removeHelp 删除问题
	 * @apiGroup help
	 * @apiName removeHelp
	 * @apiParam {int} id ID
	 * @apiParam {int} versionNo 版本号
	 * @apiVersion 1.5.0
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/removeHelp", method = RequestMethod.DELETE)
	public Tip removeHelp(@RequestBody @Validated({ Delete.class }) HelpCenterAdd helpCenterAdd) {

		helpCenterService.removeHelp(helpCenterAdd);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {GET} /help/helpDetil/{id} 问题详情
	 * @apiVersion 1.5.0
	 * @apiGroup help
	 * @apiName helpDetil
	 * @apiParam {Integer} id id
	 * @apiSuccess {String} title 标题
	 * @apiSuccess {String} typeName 问题分类名称
	 * @apiSuccess {String} isNomal 是否为常见问题
	 * @apiSuccess {String} source 来源
	 * @apiSuccess {Date} updateTime 更新时间
	 * @apiSuccess {String} updateName 更新人
	 * @apiSuccess {String} sourceZh 来源中文
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "content": "
	 *                    <p>
	 *                    sdfsdf<br/>
	 *                    </p>
	 *                    ",
	 *                    "id": 4,
	 *                    "isNomal": 1,
	 *                    "isNomalZh": "是",
	 *                    "source": "学校",
	 *                    "title": "封皮四22222发鬼地方个",
	 *                    "typeId": 5,
	 *                    "typeName": "类型6",
	 *                    "updateName": "孙先生",
	 *                    "updateTime": "2018-10-10 14:20:52",
	 *                    "versionNo": 5
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/helpDetil/{id}", method = RequestMethod.GET)
	// @Permission
	public Object helpDetil(@PathVariable("id") Long id) {

		HelpVo page = helpCenterService.findById(id);
		return SuccessTip.buildSuccess(page);
	}

}
